package com.yuntu.service.employeeInfo;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuntu.dto.EmployeeInfoDto;
import com.yuntu.mapper.employeeInfo.InfoMapper;
import com.yuntu.pojo.EmployeeInfo;
import com.yuntu.util.PageUtil;
import com.yuntu.vo.EmployeeInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dandan
 * @创建日期 2022/11/1 14:54
 * @文件描述
 */
@Service
public class InfoServiceImpl extends ServiceImpl<InfoMapper, EmployeeInfo> implements InfoService {
    @Autowired
    InfoMapper infoMapper;

    @Override
    public void getPage(PageUtil pageUtil, EmployeeInfoDto info) {
        Integer count = infoMapper.getPageCount(info);
        if (count > 0) {
            //给总条数的时，总页数会相应得出
            pageUtil.setCount(count);
            //右边界 判断当前也不能大于总页数 如果大于总页数 则将当前页重新赋值为总页数
            if (pageUtil.getPageIndex() > pageUtil.getPageCount()) {
                pageUtil.setPageIndex(pageUtil.getPageCount());
            }
            List<EmployeeInfoVo> list = infoMapper.getPage(pageUtil, info);
            pageUtil.setPageList(list);
        } else {
            List<EmployeeInfoVo> list = new ArrayList<>();
            pageUtil.setPageList(list);
        }
    }
}
